(function(window) {
	window.Wd = {
		// Application Constructor
		initialize : function() {
			$('.app').hide();			
			if (!window.device) {
				$(document).ready(Wd.onDeviceReady);
				console.log('===>> window.device');
			} else {
				Wd.bindEvents();
			}
			$(document).ready(function(){
				console.log('===>> init bind');
				//$('#btn_login').bind();
				});		
		},
		// Bind Event Listeners
		//
		// Bind any events that are required on startup. Common events are:
		// 'load', 'deviceready', 'offline', and 'online'.
		bindEvents : function() {
			document.addEventListener('deviceready', Wd.onDeviceReady, false);
			console.log('addEventListener deviceready');
		},
		// deviceready Event Handler
		//
		// The scope of 'this' is the event. In order to call the 'receivedEvent'
		// function, we must explicity call 'app.receivedEvent(...);'
		onDeviceReady : function() {
			console.log('receivedEvent deviceready');
			Wd.receivedEvent('deviceready');
		},
		// Update DOM on a Received Event
		receivedEvent : function(id) {
			var parentElement = document.getElementById(id);
			var listeningElement = parentElement.querySelector('.listening');
			var receivedElement = parentElement.querySelector('.received');

			listeningElement.setAttribute('style', 'display:none;');
			receivedElement.setAttribute('style', 'display:block;');

			console.log('Received Event: ' + id);
		}
	};
})(window);
